class Coconut
{
public:
	Coconut(void);
	~Coconut(void);
};

class Ball : public cyclone::CollisionSphere
{
public:
    Ball()
    {
        body = new cyclone::RigidBody;
		ballAlive = false;
		BALL_COLLIDE = false;
    }

    ~Ball()
    {
        delete body;
    }

	bool ballAlive;
	bool BALL_COLLIDE;
	void isALive(bool b){ ballAlive = b; }
	bool isAlive(){ return ballAlive; }

    /** Draws the box, excluding its shadow. */
    void render()
    {
        // Get the OpenGL transformation
        GLfloat mat[16];
        body->getGLTransform(mat);

		GLUquadric* sphere_quad;
		sphere_quad = gluNewQuadric();

        if (body->getAwake()) glColor3f(1.0,0.7,0.7);
        else glColor3f(0.7,0.7,1.0);

        glPushMatrix();
        glMultMatrixf(mat);
        gluSphere(sphere_quad, radius, 20, 20);
        glPopMatrix();
    }

    /** Draws the ground plane shadow for the box. */
    void renderShadow()
    {
        // Get the OpenGL transformation
        GLfloat mat[16];
        body->getGLTransform(mat);

		GLUquadric* sphere_quad;
		sphere_quad = gluNewQuadric();

        glPushMatrix();
        glScalef(1.0f, 0, 1.0f);
        glMultMatrixf(mat);
        gluSphere(sphere_quad, radius, 20, 20);
        glPopMatrix();
    }

    /** Sets the box to a specific location. */
    void setState(cyclone::Vector3 position, 
                  cyclone::Quaternion orientation, 
                  cyclone::real radius,
                  cyclone::Vector3 velocity)
    {
        body->setPosition(position);
        body->setOrientation(orientation);
        body->setVelocity(velocity);
        body->setRotation(cyclone::Vector3(0,0,0));
        Ball::radius = radius;

        cyclone::real mass = 4.0f*0.3333f*3.1415f * radius*radius*radius;
        body->setMass(mass);

        cyclone::Matrix3 tensor;
        cyclone::real coeff = 0.4f*mass*radius*radius;
        tensor.setInertiaTensorCoeffs(coeff,coeff,coeff);
        body->setInertiaTensor(tensor);

        body->setLinearDamping(0.95f);
        body->setAngularDamping(0.8f);
        body->clearAccumulators();
        body->setAcceleration(0,-10.0f,0);

        //body->setCanSleep(false);
        body->setAwake();

        body->calculateDerivedData();
    }
	//sets a default location without orientation and velocity
	void location(cyclone::Vector3 position){
		setState(
            position,
			cyclone::Quaternion(),
			1.0f,
			cyclone::Vector3()
            );
	}

    /** Positions the box at a random location. */
    void random(cyclone::Random *random)
    {
        const static cyclone::Vector3 minPos(-5, 5, -5);
        const static cyclone::Vector3 maxPos(5, 10, 5);
        cyclone::Random r;
        setState(
            random->randomVector(minPos, maxPos),
            random->randomQuaternion(),
            5.0f,
            cyclone::Vector3()
            );
    }
};